﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using OSVDB_Model;

namespace OSVDB_Logic
{
    public class Watchlist_BL
    {
        private Watchlist w_list;
        private Collection<WatchApp> app_col;

        private Collection<AbstractVuln> os_vulns;
        private Collection<AbstractVuln> packAdv_vulns;
        private Collection<AbstractVuln> packExp_vulns;
        private Collection<AbstractVuln> sec_vulns;
        private Collection<AbstractVuln> mil_vulns;

        private Collection<WatchListItem> wa_item;


        public Watchlist_BL()
        {
            w_list = new Watchlist();
            app_col = w_list.getList();
        }

        public Collection<WatchListItem> checkList()
        {
            this.wa_item = new Collection<WatchListItem>();

            if (this.os_vulns != null)
            {
                foreach (WatchApp app in app_col)
                {
                    foreach (OSVDBVulns vuln in os_vulns)
                    {
                        if (vuln.Title.Contains(app.Name))
                        {
                            WatchListItem w = new WatchListItem();
                            w.App = app.Name;
                            w.Link = vuln.Link;
                            w.Source = "OSVDB";
                            w.Title = vuln.Title;
                            w.Date = vuln.Date;

                            wa_item.Add(w);
                        }
                    }
                }
            }

            if (this.packAdv_vulns != null)
            {
                foreach (WatchApp app in app_col)
                {
                    foreach (PacketStormADV vuln in packAdv_vulns)
                    {
                        if (vuln.Description.Contains(app.Name))
                        {
                            WatchListItem w = new WatchListItem();
                            w.App = app.Name;
                            w.Link = vuln.Link;
                            w.Source = "Packet Storm Advisories";
                            w.Title = vuln.Title;
                            w.Date = DateTime.Now;

                            wa_item.Add(w);
                        }
                    }
                }
            }

            if (this.packExp_vulns != null)
            {
                foreach (WatchApp app in app_col)
                {
                    foreach (PacketStormEXP vuln in packExp_vulns)
                    {
                        if (vuln.Description.Contains(app.Name))
                        {
                            WatchListItem w = new WatchListItem();
                            w.App = app.Name;
                            w.Link = vuln.Link;
                            w.Source = "Packet Storm Exploits";
                            w.Title = vuln.Title;
                            w.Date = DateTime.Now;

                            wa_item.Add(w);
                        }
                    }
                }
            }

            if (this.sec_vulns != null)
            {
                foreach (WatchApp app in app_col)
                {
                    foreach (SecFoc vuln in sec_vulns)
                    {
                        if (vuln.Title.Contains(app.Name))
                        {
                            WatchListItem w = new WatchListItem();
                            w.App = app.Name;
                            w.Link = vuln.Link;
                            w.Source = "Security Focus";
                            w.Title = vuln.Title;
                            w.Date = vuln.Date;

                            wa_item.Add(w);
                        }
                    }
                }
            }

            if (this.mil_vulns != null)
            {
                foreach (WatchApp app in app_col)
                {
                    foreach (Milw0rm vuln in mil_vulns)
                    {
                        if (vuln.Title.Contains(app.Name))
                        {
                            WatchListItem w = new WatchListItem();
                            w.App = app.Name;
                            w.Link = vuln.Link;
                            w.Source = "Milw0rm";
                            w.Title = vuln.Title;
                            w.Date = vuln.Date;

                            wa_item.Add(w);
                        }
                    }
                }
            }

            return wa_item;
        }

        public Collection<AbstractVuln> Os_vulns
        {
            get
            {
                return this.os_vulns;
            }
            set
            {
                this.os_vulns = value;
            }
        }

        public Collection<AbstractVuln> PackAdv_vulns
        {
            get
            {
                return this.packAdv_vulns;
            }
            set
            {
                this.packAdv_vulns = value;
            }
        }

        public Collection<AbstractVuln> PackExp_vulns
        {
            get
            {
                return this.packExp_vulns;
            }
            set
            {
                this.packExp_vulns = value;
            }
        }

        public Collection<AbstractVuln> Sec_vulns
        {
            get
            {
                return this.sec_vulns;
            }
            set
            {
                this.sec_vulns = value;
            }
        }

        public Collection<AbstractVuln> Mil_vulns
        {
            get
            {
                return this.mil_vulns;
            }
            set
            {
                this.mil_vulns = value;
            }
        }
    }
}
